/* boost random_demo.cpp profane demo
 *
 * Copyright Jens Maurer 2000
 * Distributed under the Boost Software License, Version 1.0. (See
 * accompanying file LICENSE_1_0.txt or copy at
 * http://www.boost.org/LICENSE_1_0.txt)
 *
 * $Id: random_demo.cpp 28794 2005-05-10 20:40:59Z jmaurer $
 *
 * A short demo program how to use the random number library.
 */

// Integrated and adapted in 2010 by Francesco Feltrin

#ifndef _RND_GENERATOR
#define _RND_GENERATOR

#include <iostream>
#include <fstream>
#include <ctime>            // std::time

#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/uniform_real.hpp>
#include <boost/random/variate_generator.hpp>

#include <string>
#include <boost/lexical_cast.hpp> // From www.boost.org
#include <cctype>
#include <sstream>


// Sun CC doesn't handle boost::iterator_adaptor yet
#if !defined(__SUNPRO_CC) || (__SUNPRO_CC > 0x530)
#include <boost/generator_iterator.hpp>
#endif

#ifdef BOOST_NO_STDC_NAMESPACE
namespace std {
  using ::time;
}
#endif



class generator
{
   public:
       	// Define a random number generator and initialize it with a reproducible seed.
  	// (The seed is unsigned, otherwise the wrong overload may be selected
  	// when using mt19937 as the base_generator_type.)
	generator(const char* _filename = "rng.saved");
	
	generator(unsigned short min_distr_value, unsigned short max_distr_value
			  , const std::string& _filename = "rng.saved");

  	// You can save a generator's state by copy construction.
  	generator& operator=(const generator& generator);
	
	void pack();

	bool unpack();

	// This is a reproducible simulation experiment.  See main().
	void init_experiment();

        ~generator();
	
	// This is a typedef for a random number generator.
	// Try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand
	typedef boost::minstd_rand base_generator_type; 
	boost::generator_iterator< boost::variate_generator<base_generator_type&, boost::uniform_int<> > > _die;
	std::string _status_file;

protected:
	unsigned short _min_distr_value;
	unsigned short _max_distr_value;
	
private:
  	typedef boost::uniform_int<> distribution_type;
  	typedef boost::variate_generator<base_generator_type&, distribution_type> gen_type;
		
  	base_generator_type		_generator;
	gen_type *_die_gen;		
};

#endif
